package com.agriculture.monitoring.repository;

import com.agriculture.monitoring.entity.GeoDevice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface DeviceRepository extends JpaRepository<GeoDevice, Long> {
    
    Optional<GeoDevice> findByDeviceCode(String deviceCode);
    
    List<GeoDevice> findByStatus(String status);
    
    List<GeoDevice> findByDeviceType(String deviceType);
    
    @Query("SELECT d FROM GeoDevice d WHERE d.lastUpdateTime IS NOT NULL ORDER BY d.lastUpdateTime DESC")
    List<GeoDevice> findRecentActiveDevices();
}